import { http } from '@/apis/http';
import type {
	ArticleView,
	Article,
	ArticleDetail,
	ArticleCount,
	QueryArticle,
	PreviousNextArticle,
} from '@/apis/types/Article';
import type { ApiResponse, ApiResponsePage } from '@/apis/types/Response';

export const articleApi = {
	/**
	 * 获取热门文章列表
	 */
	getHotList() {
		return http.get('/content/article/hotList');
	},
	/**
	 * 获取分类文章列表（根据标签或分类查询）
	 */
	getList(query: QueryArticle) {
		return http.get<ApiResponsePage<ArticleView[]>>(
			'/content/article/getList',
			{ params: query }
		);
	},
	/**
	 * 获取文章详情
	 */
	getArticleDetail(id: number) {
		return http.get<ApiResponse<ArticleDetail>>(`/content/article/${id}`);
	},
	/**
	 * 添加文章
	 */
	addArticle(article: Article) {
		return http.post<ApiResponse<number>>(`/content/article/add`, article);
	},
	/**
	 * 更新文章
	 */
	updateArticle(article: Article) {
		return http.post<ApiResponse<Article>>(
			`/content/article/edit`,
			article
		);
	},
	/**
	 * 删除文章
	 */
	deleteArticle(id: number) {
		return http.post<ApiResponse<Article>>(`/content/article/delete/${id}`);
	},
	/**
	 * 获取文章统计
	 */
	getArticleCount() {
		return http.get<ApiResponse<ArticleCount>>(`/content/article/count`);
	},
	/**
	 * 更新文章浏览量
	 */
	updateViewCount(id: number) {
		return http.post<ApiResponse<null>>(
			`/content/article/updateViewCount/${id}`
		);
	},
	/**
	 * 获取上一篇和下一篇文章
	 */
	getPreviousNext(id: number) {
		return http.get<ApiResponse<PreviousNextArticle>>(
			`/content/article/previousNext/${id}`
		);
	},
	/**
	 * 获取置顶文章列表
	 */
	getTopList() {
		return http.get<ApiResponse<ArticleView>>(
			`/content/article/topList`
		);
	}
};
